Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Csla
Imports Csla.Data
Imports Csla.Validation

<Serializable()> _
Public Class ro_coachChild
    Inherits Csla.ReadOnlyBase(Of ro_coachChild)

#Region " Business Properties and Methods "

    ' declare members
    Private _coachId As Integer = 0
    Private _leagueId As Integer = 0
    Private _coachnameFirst As String = String.Empty
    Private _coachnameLast As String = String.Empty
    Private _coachphonePrimary As String = String.Empty
    Private _coachphoneCell As String = String.Empty
    Private _coachEmail As String = String.Empty
    Private _createDate As SmartDate = New SmartDate(DateTime.Today)

    ''' <summary>
    ''' Get the CoachId of the current object.
    ''' </summary>
    ''' <value>A Integer that represents the CoachId of the current object.</value>
    ''' <returns>Integer representing the return value.</returns>
    ''' <remarks></remarks>
    <System.ComponentModel.DataObjectField(True, True)> _
    Public ReadOnly Property CoachId() As Integer
        Get
            CanReadProperty("CoachId", True)
            Return _coachId
        End Get
    End Property

    ''' <summary>
    ''' Get the LeagueId of the current object.
    ''' </summary>
    ''' <value>A Integer that represents the LeagueId of the current object.</value>
    ''' <returns>Integer representing the return value.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property LeagueId() As Integer
        Get
            CanReadProperty("LeagueId", True)
            Return _leagueId
        End Get
    End Property

    ''' <summary>
    ''' Get the CoachnameFirst of the current object.
    ''' </summary>
    ''' <value>A String that represents the CoachnameFirst of the current object.</value>
    ''' <returns>String representing the return value.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property CoachnameFirst() As String
        Get
            CanReadProperty("CoachnameFirst", True)
            Return _coachnameFirst
        End Get
    End Property

    ''' <summary>
    ''' Get the CoachnameLast of the current object.
    ''' </summary>
    ''' <value>A String that represents the CoachnameLast of the current object.</value>
    ''' <returns>String representing the return value.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property CoachnameLast() As String
        Get
            CanReadProperty("CoachnameLast", True)
            Return _coachnameLast
        End Get
    End Property

    ''' <summary>
    ''' Get the CoachphonePrimary of the current object.
    ''' </summary>
    ''' <value>A String that represents the CoachphonePrimary of the current object.</value>
    ''' <returns>String representing the return value.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property CoachphonePrimary() As String
        Get
            CanReadProperty("CoachphonePrimary", True)
            Return _coachphonePrimary
        End Get
    End Property

    ''' <summary>
    ''' Get the CoachphoneCell of the current object.
    ''' </summary>
    ''' <value>A String that represents the CoachphoneCell of the current object.</value>
    ''' <returns>String representing the return value.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property CoachphoneCell() As String
        Get
            CanReadProperty("CoachphoneCell", True)
            Return _coachphoneCell
        End Get
    End Property

    ''' <summary>
    ''' Get the CoachEmail of the current object.
    ''' </summary>
    ''' <value>A String that represents the CoachEmail of the current object.</value>
    ''' <returns>String representing the return value.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property CoachEmail() As String
        Get
            CanReadProperty("CoachEmail", True)
            Return _coachEmail
        End Get
    End Property

    ''' <summary>
    ''' Get the CreateDate of the current object.
    ''' </summary>
    ''' <value>A DateTime that represents the CreateDate of the current object.</value>
    ''' <returns>DateTime representing the return value.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property CreateDate() As DateTime
        Get
            CanReadProperty("CreateDate", True)
            Return _createDate.Date
        End Get
    End Property

    ''' <summary>
    ''' Get the CreateDateString of the current object.
    ''' </summary>
    ''' <value>A String that represents the CreateDateString of the current object.</value>
    ''' <returns>String representing the return value.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property CreateDateString() As String
        Get
            CanReadProperty("CreateDateString", True)
            Return _createDate.Text
        End Get
    End Property

    ''' <summary>
    ''' Get the unique id for the current object.
    ''' </summary>
    ''' <returns>A value that is the unique id of the object.</returns>
    ''' <remarks></remarks>
    Protected Overrides Function GetIdValue() As Object
        Return _coachId
    End Function

    Public Overrides Function ToString() As String
        Return _coachnameFirst & " " & _coachnameLast
    End Function
#End Region ' Business Properties and Methods

#Region " Authorization Rules "

    Protected Overrides Sub AddAuthorizationRules()
        'TODO: Define authorization rules in ro_coachChild
        'AuthorizationRules.AllowRead("CoachId", "ro_coachChildReadGroup")
        'AuthorizationRules.AllowRead("LeagueId", "ro_coachChildReadGroup")
        'AuthorizationRules.AllowRead("CoachnameFirst", "ro_coachChildReadGroup")
        'AuthorizationRules.AllowRead("CoachnameLast", "ro_coachChildReadGroup")
        'AuthorizationRules.AllowRead("CoachphonePrimary", "ro_coachChildReadGroup")
        'AuthorizationRules.AllowRead("CoachphoneCell", "ro_coachChildReadGroup")
        'AuthorizationRules.AllowRead("CoachEmail", "ro_coachChildReadGroup")
        'AuthorizationRules.AllowRead("CreateDate", "ro_coachChildReadGroup")
        'AuthorizationRules.AllowRead("CreateDateString", "ro_coachChildReadGroup")

    End Sub

#End Region ' Authorization Rules

#Region " Factory Methods "

    Friend Shared Function Getro_coachChild(ByVal dr As SafeDataReader) As ro_coachChild
        Return New ro_coachChild(dr)
    End Function

    Private Sub New(ByVal dr As SafeDataReader)
        Fetch(dr)
    End Sub

#End Region ' Factory Methods

#Region " Data Access "

#Region " Data Access - Fetch "

    Private Sub Fetch(ByVal dr As SafeDataReader)
        FetchObject(dr)

        'load child object(s)
        FetchChildren(dr)
    End Sub

    Private Sub FetchObject(ByVal dr As SafeDataReader)
        _coachId = dr.GetInt32("coachId")
        _leagueId = dr.GetInt32("leagueId")
        _coachnameFirst = dr.GetString("coachName_first")
        _coachnameLast = dr.GetString("coachName_last")
        _coachphonePrimary = dr.GetString("coachPhone_primary")
        _coachphoneCell = dr.GetString("coachPhone_cell")
        _coachEmail = dr.GetString("coachEmail")
        _createDate = dr.GetSmartDate("createDate", _createDate.EmptyIsMin)
    End Sub

    Private Sub FetchChildren(ByVal dr As SafeDataReader)
    End Sub

#End Region ' Data Access - Fetch

#End Region

End Class

